﻿package com.jfdesgagne.jfdesgagne09.core.view {
	import flash.display.Sprite;
	import flash.text.TextFieldAutoSize;
	import flash.display.MovieClip;
	import flash.display.BitmapData;
	import fl.lang.Locale;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import gs.*; 
	import gs.easing.*;
	
	public class FrameView extends Sprite {
		private var _logo_mc:MovieClip;
		private var _top_sp:Sprite;
		private var _topBg_mc:MovieClip;
		private var _mainMenu_sp:Sprite;
		public var mainMenuItems_array:Array;
		
		private var _bottom_sp:Sprite;
		private var _bottomMenu_sp:Sprite;
		private var _bottomBg_mc:MovieClip;
		public var bottomMenuItems_array:Array;
					
		private var _copyright_mc:MovieClip;
		private var _email:String;
		
		public function FrameView(_email:String) {
			this._email = _email;
		}
		
		public function init():void {
			this.initTop();
			this.initMainMenu();
			this.initBottom();
			this.initBottomMenu();
		}
		
		private function initBottom():void {
			this._bottom_sp = new Sprite();
			this.addChild(this._bottom_sp);
			
			this._bottomBg_mc = new ShadowBottomMc();
			this._bottomBg_mc.width = this.stage.stageWidth;
			this._bottom_sp.addChild(this._bottomBg_mc);
			this._bottom_sp.y = this.stage.stageHeight - this._bottom_sp.height;
			
			this._copyright_mc = new CopyrightMc();
			this._bottom_sp.addChild(this._copyright_mc);
			this._copyright_mc.y = this._bottom_sp.height - this._copyright_mc.height - 10;
			this._copyright_mc.x = 30;
		}
		
		private function initBottomMenu():void {
			this.bottomMenuItems_array = new Array();
			this._bottomMenu_sp = new Sprite();
			this._bottom_sp.addChild(this._bottomMenu_sp);
			this.createBottomMenuItem("IDS_BOTTOMMENU_TOOLTIP", "T");
			this.createBottomMenuItem("IDS_BOTTOMMENU_FULLSCREEN", "F");
			this.createBottomMenuItem("IDS_BOTTOMMENU_HELP", "H", true);
			this._bottomMenu_sp.y = this._bottom_sp.height - this._bottomMenu_sp.height - 10;
			this._bottomMenu_sp.x = this._bottom_sp.width - this._bottomMenu_sp.width - 30;
		}
		
		private function createBottomMenuItem(name:String, letter:String, _noBorder:Boolean=false):MovieClip {
			var itemBg_mc:MovieClip = new MovieClip();
				itemBg_mc.alpha = 0;
				itemBg_mc.graphics.beginFill(0xfff600, 1);
				itemBg_mc.graphics.drawRect(0, 0, 1, 1);
				itemBg_mc.graphics.endFill();
			this._bottomMenu_sp.addChild(itemBg_mc);
			
			var item_mc:MovieClip = new BottomMenuMc();
				item_mc.letter_txt.text 	= letter;
				item_mc.label_txt.htmlText 	= Locale.loadString(name);
				item_mc.label_txt.autoSize	= TextFieldAutoSize.LEFT;
				item_mc.letter = letter;
				item_mc.tooltip = name+"_TOOLTIP";
				
			this._bottomMenu_sp.addChild(item_mc);
			if(this.bottomMenuItems_array.length>0) item_mc.x = this.bottomMenuItems_array[this.bottomMenuItems_array.length-1].x+ this.bottomMenuItems_array[this.bottomMenuItems_array.length-1].width+30; 
			this.bottomMenuItems_array.push(item_mc);
			
			if(!_noBorder) {
				this._bottomMenu_sp.graphics.lineStyle(1, 0x4d4d4d);
				this._bottomMenu_sp.graphics.moveTo(item_mc.x+item_mc.width+15, 5);
				this._bottomMenu_sp.graphics.lineTo(item_mc.x+item_mc.width+15, 20);
				this._bottomMenu_sp.graphics.endFill();
			}
			
			item_mc.graphics.beginFill(0xfff600, 0);
			item_mc.graphics.drawRect(0, 0, item_mc.width, item_mc.height);
			item_mc.graphics.endFill();
			item_mc.buttonMode = true;
			item_mc.mouseChildren = false;
			item_mc.initWidth 		= item_mc.width;
			item_mc.itemBg_mc 		= itemBg_mc;
			itemBg_mc.x = item_mc.x;
			itemBg_mc.y = item_mc.y;
			
			return item_mc;
		}
		
		private function initTop():void {
			this._top_sp = new Sprite();
			this.addChild(this._top_sp);
			
			this._topBg_mc = new ShadowTopMc();
			this._topBg_mc.width = this.stage.stageWidth;
			this._top_sp.addChild(this._topBg_mc);
			
			this._logo_mc = new LogoMc();
			this._logo_mc.subTitle_txt.autoSize = TextFieldAutoSize.LEFT;
			this._logo_mc.subTitle_txt.text = Locale.loadString("IDS_LOGO_SUBTITLE");
			this._logo_mc.x = 30;
			this._logo_mc.y = 10;
			this._logo_mc.buttonMode = true;
			this._logo_mc.mouseChildren = false;
			this._top_sp.addChild(this._logo_mc);	
		}
		
		private function initMainMenu():void {
			this._mainMenu_sp = new Sprite();
			this.mainMenuItems_array = new Array();
			this.createMainMenuItem("IDS_MAINMENU_PROJECTSSHOWCASE", "A");
			this.createMainMenuItem("IDS_MAINMENU_PROFILE", "B");
			this.createMainMenuItem("IDS_MAINMENU_BLOG", "C");
			this.createMainMenuItem("IDS_MAINMENU_CONTACT", "D", true);
			this.addChild(this._mainMenu_sp);
			this._mainMenu_sp.x = this.stage.stageWidth - this._mainMenu_sp.width - 30;
			this._mainMenu_sp.y = 20;
		}
		
		private function createMainMenuItem(name:String, letter:String, isContact:Boolean=false):MovieClip {
			var itemBg_mc:MovieClip = new MovieClip();
				itemBg_mc.alpha = 0;
				itemBg_mc.graphics.beginFill(0xfff600, 1);
				itemBg_mc.graphics.drawRect(0, 0, 1, 1);
				itemBg_mc.graphics.endFill();
			this._mainMenu_sp.addChild(itemBg_mc);
			
			var item_mc:MovieClip = new MainMenuMc();
				item_mc.label_txt.text 	= Locale.loadString(name);
				item_mc.label_txt.autoSize	= TextFieldAutoSize.LEFT;
				item_mc.letter_txt.text 	= letter;
				item_mc.letter = letter;
				item_mc.tooltip = name+"_TOOLTIP";
				
			this._mainMenu_sp.addChild(item_mc);
			if(this.mainMenuItems_array.length>0) item_mc.x = item_mc.parent.width+10; 
			this.mainMenuItems_array.push(item_mc);
			
			if(isContact) {
				item_mc.email_txt.alpha = 1;
				item_mc.email_txt.autoSize = TextFieldAutoSize.LEFT;
				item_mc.email_txt.text = this._email;
				item_mc.email_txt.width = 100;
			} else {
				item_mc.email_txt.alpha = 0;
				item_mc.label2_txt.text 	= Locale.loadString(name+"2");
				item_mc.label2_txt.autoSize	= TextFieldAutoSize.LEFT;
				
				this._mainMenu_sp.graphics.lineStyle(1, 0x4d4d4d);
				this._mainMenu_sp.graphics.moveTo(item_mc.x+item_mc.width+10, 5);
				this._mainMenu_sp.graphics.lineTo(item_mc.x+item_mc.width+10, 30);
				this._mainMenu_sp.graphics.endFill();
			}
			
			item_mc.graphics.beginFill(0xfff600, 0);
			item_mc.graphics.drawRect(0, 0, item_mc.width, item_mc.height);
			item_mc.graphics.endFill();
			item_mc.buttonMode 		= true;
			item_mc.mouseChildren 	= false;
			item_mc.initWidth 		= item_mc.width;
			item_mc.itemBg_mc 		= itemBg_mc;
			itemBg_mc.x = item_mc.x;
			itemBg_mc.y = item_mc.y;
				
			return item_mc;
		}
		
		public function mainMenuItemRollOver(clip_mc:MovieClip):void {
			trace("mainMenuItemRollOverHandler:" + clip_mc.itemBg_mc.x);
			clip_mc.itemBg_mc.alpha = 1;
			clip_mc.itemBg_mc.x = clip_mc.x-5;
			clip_mc.itemBg_mc.y = 4;
			clip_mc.itemBg_mc.height = 27;
			clip_mc.itemBg_mc.width = 0;
			TweenLite.to(clip_mc.itemBg_mc, 0.5, {width:clip_mc.initWidth+10, ease:Expo.easeOut});
			TweenLite.to(clip_mc, 0.2, {tint:0x000000, ease:Back.easeOut});
		}
		
		public function mainMenuItemRollOut(clip_mc:MovieClip):void {
			TweenLite.to(clip_mc, 0.1, {removeTint:true, ease:Back.easeOut});
			TweenLite.to(clip_mc.itemBg_mc, 0.1, {width:0, ease:Expo.easeOut});
		}
		
		public function bottomMenuItemRollOver(clip_mc:MovieClip):void {
			trace("mainMenuItemRollOverHandler:" + clip_mc.itemBg_mc.x);
			clip_mc.itemBg_mc.alpha = 1;
			clip_mc.itemBg_mc.x = clip_mc.x-5;
			clip_mc.itemBg_mc.y = 2;
			clip_mc.itemBg_mc.height = 22;
			clip_mc.itemBg_mc.width = 0;
			TweenLite.to(clip_mc.itemBg_mc, 0.5, {width:clip_mc.initWidth+10, ease:Expo.easeOut});
			TweenLite.to(clip_mc, 0.2, {tint:0x000000, ease:Back.easeOut});
		}
		
		public function bottomMenuItemRollOut(clip_mc:MovieClip):void {
			TweenLite.to(clip_mc, 0.1, {removeTint:true, ease:Back.easeOut});
			TweenLite.to(clip_mc.itemBg_mc, 0.1, {width:0, ease:Expo.easeOut});
		}
		
		public function resize(event:Event):void {
			this._bottomBg_mc.width = this.stage.stageWidth;
			this._bottom_sp.y = this.stage.stageHeight - this._bottom_sp.height;
			this._topBg_mc.width = this.stage.stageWidth;
			
			TweenLite.to(this._bottomMenu_sp, 1, {x:this.stage.stageWidth - this._bottomMenu_sp.width - 30, ease:Expo.easeOut});
			TweenLite.to(this._mainMenu_sp, 1, {x:this.stage.stageWidth - this._mainMenu_sp.width - 30, ease:Expo.easeOut});
		}
	}
	
}